package yto.freemarker.springcloud.service;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import yto.freemarker.springcloud.entity.SecurityUser;

/**
 * @author dongxing
 * @create 2018-03-02 10:26
 **/
@Component
public class CustomUserDetailService implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        if ("user".equals(username)){
            return new SecurityUser("user", "password1", "user-role");
        }else if ("admin".equals(username)){
            return new SecurityUser("admin", "password2", "admin-role");
        }else {
            return null;
        }
    }
}
